<?php

// +----------------------------------------------------------------------
// | Admin Plugin for ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/think-plugs-admin
// | github 代码仓库：https://github.com/zoujingli/think-plugs-admin
// +----------------------------------------------------------------------

namespace app\admin\controller;
use app\model\UserDao;
use think\admin\Controller;

/**
 * 用户管理
 * @class User
 * @package app\admin\controller
 */
class User extends Controller
{
    protected $table = '';

    protected function initialize()
    {
        $this->table = UserDao::query();
    }


    /**
     * 用户管理
     * @auth true
     * @menu true
     */
    public function index()
    {
        $this->title = '用户管理';
        $this->_query($this->table)
            ->like('usernmae,mobile')
            ->equal('status')
            ->order('sort DESC,id ASC')
            ->dateBetween('create_at')
            ->page();
    }

    protected function _page_filter(&$list)
    {
        // dump($list);
        // die();
    }


    /**
     * 添加
     * @auth true
     */
    public function add()
    {
        $this->_form($this->table, 'form');
    }

    /**
     * 编辑系
     * @auth true
     */
    public function edit()
    {
        $this->_form($this->table, 'form');
    }


    protected function _form_filter(&$data)
    {
        if ($this->request->isGet()) {
            if (!empty($data['pics'])) {
                $data['pics'] = str_replace(',', '|', $data['pics']);
            }
        } else {
            if (!empty($data['pics'])) {
                $data['pics'] = str_replace('|', ',', $data['pics']);
            }
        }
    }

    protected function _form_result(&$result, &$data)
    {
        if ($result !== false) {
            //$cateId = $data['cate_id'] ?? 0;
            //$spm = $data['spm'] ?? 0;
            //jumpUrl(1, '操作成功', '/admin.html#/admin/news/index.html?&spm='.$spm);
        }
    }

    /**
     * @auth true
     */
    public function remove()
    {
        $this->_applyFormToken();
        $this->_delete($this->table);
    }


    /**
     * 修改
     * @auth true
     */
    public function state()
    {
        $this->_save($this->table, $this->_vali([
            'status.in:0,1' => '状态值范围异常！',
            'status.require' => '状态值不能为空！',
        ]));
    }
}
